package com.ms.game.characterInfo.db;

import java.sql.Date;
import java.util.List;

import com.ms.game.characterInfo.DailyExchange;
import com.ms.game.characterInfo.message.DailyExchangeResponse;
import com.ms.service.error.ErrorCode;
import com.ms.service.module.zone.BlockType;
import com.ms.service.module.zone.module.BasicZoneModule;
import com.xpec.c4.game.utility.GUID;
import com.xpec.c4.message.MessageTypes;
import com.xpec.c4.service.message.MessageAction;
import com.xpec.c4.service.module.BasicServiceModule;
import com.xpec.c4.service.module.datacenter.player.db.DailyExchangeLogModel;
import com.xpec.c4.service.module.task.TaskAsyncCommand;

/**
 * 依照日期查詢日常收支資料
 *
 */
public class GetDailyExchangeAsync extends TaskAsyncCommand {

	public GUID playerID;
	
	public GUID sessionID;
	
	/**
	 * 日期
	 */
	public Long date;
	
	/**
	 * 回傳消息
	 */
	public DailyExchangeResponse response;
	
	@Override
	public void asyncExecute() throws Exception {
		
		Date dateTime = new Date(date);
		//日期查詢後結果
		List<DailyExchangeLogModel> list = DailyExchangeLogDAO.loadDailyExchangeByGuidAndDateTime(playerID, dateTime);
		response.dExchange.clear();
		for(DailyExchangeLogModel log : list)
		{
			DailyExchange dExchange = new DailyExchange(log);
			response.dExchange.add(dExchange);
		}

		//回傳查詢結果
		response.errorCode = ErrorCode.SUCCESS;
		MessageAction.sendMessage(sessionID, MessageTypes.S_GET_DAILY_EXCHANGE_RESPONSE, response);
	}

	@Override
	public void execute() throws Exception {
		BasicServiceModule module = getCurrentModuleServer();
		if (module instanceof BasicZoneModule) {
			BasicZoneModule zoneModule = (BasicZoneModule) module;
			zoneModule.getZone().removeBlockList(playerID, BlockType.SUBKEY_GET_DAILY_EXCHANGE);
		}
	}
}
